package com.brother.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.brother.Constants;
import com.brother.http.HttpSessionCopy;
import com.brother.model.Customer;

public class WebServiceFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) arg0;
		HttpServletResponse res = (HttpServletResponse) arg1;
		req.setCharacterEncoding("UTF-8");
		String url = req.getRequestURI();
		HttpSession session = req.getSession();
		Customer c = (Customer) session.getAttribute(Constants.LOGIN_SESSTION_NAME2);

//		if(c == null && url.indexOf("login") == -1){ // 没有登录
//			res.getOutputStream().write("{\"status\":-1}".getBytes());
//			return;
//		}
		HttpSessionCopy.session.set(session);
		arg2.doFilter(req, res);

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
